package Ontologies;

import jade.content.onto.BasicOntology;
import jade.content.onto.Ontology;
import jade.content.schema.AgentActionSchema;
import jade.content.schema.ConceptSchema;
import jade.content.schema.ObjectSchema;
import jade.content.schema.PrimitiveSchema;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jiaka_000
 * Date: 13-5-9
 * 
 * the ontology for the fruit tree system
 * it contains all necessary information about entity concept, query action, purchase action and response.
 * the list for  all available trees are also provided by the ontology.
 */
public class FruitTreeNurserySystemOntology extends Ontology implements FruitTreeVocabulary{
    /**
     * the name of this ontology
     */
    public static final String NAME = "FTN-System-Ontology";

    /**
     *  The singleton instance of the Time-Ontology
     */
    private static FruitTreeNurserySystemOntology theInstance = new FruitTreeNurserySystemOntology();

    public static Ontology getInstance() {
        return theInstance;
    }

    /**
     * the static comparing method to determine whether two trees are same type or not
     *
     * @param targetTree: the target tree from request
     * @param tree : the tree in the agent's list
     */
    public static boolean isSameTreeType(TreeWithPrice targetTree, TreeWithPrice tree) {
        return tree.getCommonName().equalsIgnoreCase(targetTree.getCommonName()) ||
                tree.getLatinName().equalsIgnoreCase(targetTree.getLatinName());
    }

    /**
     * the method returns a list of all available trees.
     * at this stage, all trees are hard coded.
     */
    public List<TreeWithPrice> getAllTreesList() {

        List<TreeWithPrice> treesList=new ArrayList<TreeWithPrice>();
        TreeWithPrice tree=new TreeWithPrice("Musk Mallow","Abelmoschus moschatus tuberosus","native fruiting trees",(float)12.9,-1);
        treesList.add(tree);
        tree=new TreeWithPrice("Burdekin Plum","Pleiogynium timorense","native fruiting trees",(float)14.9,-1);
        treesList.add(tree);
        tree=new TreeWithPrice("Plum Pine","Podocarpus elatus","native fruiting trees",(float)12.9,-1);
        treesList.add(tree);
        tree=new TreeWithPrice("Blueberry","Vaccinium spp","exotic fruiting trees",(float)14.9,-1);
        treesList.add(tree);
        tree=new TreeWithPrice("Grape","Vitus vinifera","exotic fruiting trees",(float)9.9,-1);
        treesList.add(tree);
        tree=new TreeWithPrice("Acerola Cherry - Florida Sweet","Malpighia emarginata","rainforest fruiting trees",(float)19.75,-1);
        treesList.add(tree);
        tree=new TreeWithPrice("Madrono","Garcinia madruno","rainforest fruiting trees",(float)19.9,-1);
        treesList.add(tree);
        tree=new TreeWithPrice("Jakfruit","Artocarpus heterophyllus","rainforest fruiting trees",(float)17.9,-1);
        treesList.add(tree);

        return   treesList;
    }

    /**
     * the private constructor for ontology, not opened for others
     */
    private FruitTreeNurserySystemOntology() {
        super(NAME,BasicOntology.getInstance());

        try {
            // Add all Concepts, Predicates and AgentActions in the local package
           // add(getClass().getPackage().getName());

            // ------- Add Concepts
            // Tree
            ConceptSchema cs = new ConceptSchema(TREE);
            add(cs, TreeWithPrice.class);
            cs.add(TREE_COMMON_NAME, (PrimitiveSchema) getSchema(BasicOntology.STRING), ObjectSchema.MANDATORY);
            cs.add(TREE_LATIN_NAME, (PrimitiveSchema) getSchema(BasicOntology.STRING), ObjectSchema.MANDATORY);
            cs.add(TREE_CATEGORY, (PrimitiveSchema) getSchema(BasicOntology.STRING), ObjectSchema.MANDATORY);
            cs.add(TREE_UNIT_PRICE, (PrimitiveSchema) getSchema(BasicOntology.FLOAT), ObjectSchema.MANDATORY);
            cs.add(TREE_QUANTITY, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), ObjectSchema.MANDATORY);

            //purchase response
            cs = new ConceptSchema(PURCHASE_RESPONSE);
            add(cs, PurchaseResponse.class);
            cs.add(ERROR_CODE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), ObjectSchema.MANDATORY);
            cs.add(TREE_COMMON_NAME, (PrimitiveSchema) getSchema(BasicOntology.STRING), ObjectSchema.MANDATORY);
            cs.add(TREE_LATIN_NAME, (PrimitiveSchema) getSchema(BasicOntology.STRING), ObjectSchema.MANDATORY);
            cs.add(TREE_UNIT_PRICE, (PrimitiveSchema) getSchema(BasicOntology.FLOAT), ObjectSchema.MANDATORY);
            cs.add(TREE_QUANTITY, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), ObjectSchema.MANDATORY);

            // ------- Add query action
            AgentActionSchema as = new AgentActionSchema(QUERY_ACTION);
            add(as, QueryAction.class);
            as.add(TREE_COMMON_NAME, (PrimitiveSchema) getSchema(BasicOntology.STRING), ObjectSchema.MANDATORY);
            as.add(TREE_LATIN_NAME, (PrimitiveSchema) getSchema(BasicOntology.STRING), ObjectSchema.MANDATORY);

            // ------- Add purchase action
            as = new AgentActionSchema(PURCHASE_ACTION);
            add(as, PurchaseAction.class);
            as.add(TREE_COMMON_NAME, (PrimitiveSchema) getSchema(BasicOntology.STRING), ObjectSchema.MANDATORY);
            as.add(TREE_LATIN_NAME, (PrimitiveSchema) getSchema(BasicOntology.STRING), ObjectSchema.MANDATORY);
            as.add(TREE_QUANTITY, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), ObjectSchema.MANDATORY);

        }
        catch (Exception e) {
            //e.printStackTrace();
        }
    }
}
